<template>
  <div v-if="viewpageShow">
    <el-dialog title="图纸修改" :visible.sync="viewpageShow" width="65%" append-to-body>
      <basic-container>
        <el-divider content-position="left"><i class="el-icon-arrow-down"></i> 详情数据</el-divider>
        <el-form :inline="true" :model="formInline" class="demo-form-inline" size="small" ref="searchForm"
          style="margin-top: 30px">
          <el-row>
            <el-col :span="6">
              <el-form-item label="设备代号" prop="drawingNumber">
                <el-input placeholder="设备代号" clearable v-model="formInline.drawingNumber" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="设备名称" prop="drawingName">
                <el-input placeholder="设备名称" clearable v-model="formInline.drawingName" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="设备材料" prop="material">
                <el-input placeholder="设备材料" clearable v-model="formInline.material" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="图纸备注" prop="drawingRemark">
                <el-select v-model="formInline.drawingRemark" placeholder="请选择图纸备注" disabled>
                  <el-option v-for="(item) in drawingRemarkList" :key="item.id" :label="item.dictValue"
                    v-bind:value="item.dictValue"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="特征值一" prop="characOne">
                <el-input placeholder="特征值一" clearable v-model="formInline.characOne" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="特征值二" prop="characTwo">
                <el-input placeholder="特征值二" clearable v-model="formInline.characTwo" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="特征值三" prop="characThree">
                <el-input placeholder="特征值三" clearable v-model="formInline.characThree" readonly></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="图纸类型" prop="drawingType">
                <el-select v-model="formInline.drawingType" placeholder="请选择图纸类型" disabled>
                  <el-option v-for="(item) in drawingTypeList" :key="item.id" :label="item.name"
                    v-bind:value="item.code"></el-option>
                </el-select>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="8"></el-col>
            <el-col :span="8">
              <el-form-item>
                <el-button type="primary" size="small" icon="el-icon-edit" @click="onUpdate">修改图面</el-button>
                <el-button type="primary" size="small" icon="el-icon-edit" @click="onSubmit">图纸下线</el-button>
              </el-form-item>
            </el-col>
            <el-col :span="8"></el-col>
          </el-row>
        </el-form>

        <!--修改图面信息-->
        <el-dialog title="图纸信息" :visible.sync="updateDrawingBox" append-to-body width="65%">
          <el-form :inline="true" :model="formInline" class="demo-form-inline" size="small" ref="searchForm">
            <el-row>
              <el-col :span="6">
                <el-form-item label="设备代号" prop="drawingNumber">
                  <el-input placeholder="设备代号" clearable v-model="formInline.drawingNumber" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="设备名称" prop="drawingName">
                  <el-input placeholder="设备名称" clearable v-model="formInline.drawingName" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="设备材料" prop="material">
                  <el-input placeholder="设备材料" clearable v-model="formInline.material"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="图纸备注" prop="drawingRemark">
                  <el-select v-model="formInline.drawingRemark" placeholder="请选择图纸备注" disabled>
                    <el-option v-for="(item) in drawingRemarkList" :key="item.id" :label="item.dictValue"
                      v-bind:value="item.dictValue"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="特征值一" prop="characOne">
                  <el-input placeholder="特征值一" clearable v-model="formInline.characOne"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="特征值二" prop="characTwo">
                  <el-input placeholder="特征值二" clearable v-model="formInline.characTwo"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="特征值三" prop="characThree">
                  <el-input placeholder="特征值三" clearable v-model="formInline.characThree"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="图纸类型" prop="drawingType">
                  <el-select v-model="formInline.drawingType" placeholder="请选择图纸类型" disabled>
                    <el-option v-for="(item) in drawingTypeList" :key="item.id" :label="item.name"
                      v-bind:value="item.code"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

            </el-row>
          </el-form>
          <span slot="footer" class="dialog-footer">
            <el-button @click="updateDrawingBox = false" size="small" icon="el-icon-close">取 消</el-button>
            <el-button type="primary" size="small" icon="el-icon-check" @click="submitUpdate">确 定</el-button>
          </span>
        </el-dialog>

        <!--修改图纸信息-->
        <el-dialog title="图纸信息" :visible.sync="drawingBox" append-to-body width="65%">
          <el-form :inline="true" :model="formInline" class="demo-form-inline" size="small" ref="searchForm">
            <el-row>
              <el-col :span="6">
                <el-form-item label="设备代号" prop="drawingNumber">
                  <el-input placeholder="设备代号" clearable v-model="formInline.drawingNumber" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="设备名称" prop="drawingName">
                  <el-input placeholder="设备名称" clearable v-model="formInline.drawingName" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="设备材料" prop="material">
                  <el-input placeholder="设备材料" clearable v-model="formInline.material" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="图纸备注" prop="drawingRemark">
                  <el-select v-model="formInline.drawingRemark" placeholder="请选择图纸备注" disabled>
                    <el-option v-for="(item) in drawingRemarkList" :key="item.id" :label="item.dictValue"
                      v-bind:value="item.dictValue"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="特征值一" prop="characOne">
                  <el-input placeholder="特征值一" clearable v-model="formInline.characOne" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="特征值二" prop="characTwo">
                  <el-input placeholder="特征值二" clearable v-model="formInline.characTwo" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="特征值三" prop="characThree">
                  <el-input placeholder="特征值三" clearable v-model="formInline.characThree" readonly></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="图纸类型" prop="drawingType">
                  <el-select v-model="formInline.drawingType" placeholder="请选择图纸类型" clearable>
                    <el-option v-for="(item) in drawingTypeList" :key="item.id" :label="item.name"
                      v-bind:value="item.code"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>

            </el-row>
            <el-row>
              <el-col :span="10"></el-col>
              <el-col :span="6">
                <el-form-item>
                  <el-button type="primary" size="small" icon="el-icon-edit" @click="innerDialog">图纸下线</el-button>
                  <el-button type="primary" size="small" icon="el-icon-edit" @click="drawingBox = false">关闭</el-button>
                </el-form-item>
              </el-col>
              <el-col :span="8"></el-col>
            </el-row>
          </el-form>
          <el-divider content-position="left">关联上级设备信息</el-divider>
          <el-table :data="superTableData" border style="width: 100%" size="small" height="200" stripe
            :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}">
            <el-table-column prop="drawingNumber" label="图纸编号"></el-table-column>
            <el-table-column prop="drawingName" label="图纸名称"></el-table-column>
            <el-table-column prop="material" label="材料"></el-table-column>
            <el-table-column prop="drawingProperty" label="属性"></el-table-column>
            <el-table-column prop="drawingRemark" label="备注"></el-table-column>
            <el-table-column prop="characOne" label="特征值一"></el-table-column>
            <el-table-column prop="characTwo" label="特征值二"></el-table-column>
            <el-table-column prop="characThree" label="特征值三"></el-table-column>
          </el-table>
          <el-divider content-position="left">关联下级设备信息</el-divider>
          <el-table :data="subTableData" border style="width: 100%" size="small" height="200" stripe
            :header-cell-style="{'text-align':'center'}" :cell-style="{'text-align':'center'}">
            <el-table-column prop="drawingNumber" label="图纸编号"></el-table-column>
            <el-table-column prop="drawingName" label="图纸名称"></el-table-column>
            <el-table-column prop="material" label="材料"></el-table-column>
            <el-table-column prop="drawingProperty" label="属性"></el-table-column>
            <el-table-column prop="drawingRemark" label="备注"></el-table-column>
            <el-table-column prop="characOne" label="特征值一"></el-table-column>
            <el-table-column prop="characTwo" label="特征值二"></el-table-column>
            <el-table-column prop="characThree" label="特征值三"></el-table-column>
          </el-table>
          <el-dialog width="30%" title="内层 Dialog" :visible.sync="innerVisible" append-to-body>
          </el-dialog>

        </el-dialog>


      </basic-container>
    </el-dialog>
  </div>
</template>

<script>
  import { getDrawingTypeList, getDictValueList, getDrawingInfoByNodeId } from "@/api/resource/attach";
  import { updateDrawingInfo, getAllDrawingInfo, offlineDrawingInfo } from "@/api/drawing/drawingdetail";
  export default {
    name: "drawingdetail",
    data() {
      return {
        // 图面信息修改
        updateDrawingBox: false,
        // 图纸修改
        drawingBox: false,
        superTableData: [],
        subTableData: [],
        innerVisible: false,
        formInline: {
          drawingNumber: '',
          drawingName: '',
          material: '',
          drawingProperty: '',
          drawingRemark: '',
          characOne: '',
          characTwo: '',
          characThree: '',
          drawingType: '',
        },
        drawingTypeList: [],
        // 备注
        drawingRemarkList: [],
        drawId: '',
        viewpageShow: false,
      }
    },
    /*   created() {
        this.getDrawingTypeListFun();
        this.drawingTypeListFun();
        this.getDetail();
        this.getAllDrawingInfoFun();
      }, */
    methods: {

      setDrawId(id) {
        this.drawId = id;
      },
      initData() {
        this.superTableData = [];
        this.subTableData = [];
        this.formInline = [];
        this.drawingTypeList = [];
        this.drawingRemarkList = [];
      },

      parentCreated() {
        this.getDrawingTypeListFun();
        this.drawingTypeListFun();
        this.getDetail();
        this.getAllDrawingInfoFun();
        this.viewpageShow = true;
      },
      // 修改图纸信息
      innerDialog() {
        this.$confirm("确定下线此图纸?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          // this.innerVisible = true;
          offlineDrawingInfo(this.formInline).then(() => {
            this.$message({
              type: 'success',
              message: "图纸下线成功!"
            });
            this.drawingBox = false;
          });
        })
      },

      // 修改图纸的图面信息
      onUpdate() {
        this.updateDrawingBox = true;
      },
      // 提交修改的图面信息
      submitUpdate() {
        let formValue = this.formInline;
        updateDrawingInfo(formValue).then(() => {
          this.$message({
            type: 'success',
            message: "操作成功!"
          });
          this.getDetail();
          this.updateDrawingBox = false;
        });
      },
      // 修改图纸的图面信息
      onSubmit() {
        this.drawingBox = true;
        this.getAllDrawingInfoFun();

      },
      // 展示所有的关联的节点信息
      getAllDrawingInfoFun() {
        getAllDrawingInfo(this.drawId).then((res) => {
          if (res.data.data["super"] != null) {
            this.superTableData = res.data.data["super"];
          }
          if (res.data.data["sub"] != null) {
            this.subTableData = res.data.data["sub"];
          }
        })
      },
      getDetail() {
        getDrawingInfoByNodeId(this.drawId).then(res => {
          this.formInline = res.data.data;
        })
      },
      getDrawingTypeListFun() {
        getDrawingTypeList().then(res => {
          this.drawingTypeList = res.data.data;
        })
      },
      drawingTypeListFun() {
        getDictValueList("drawing_remark").then(res => {
          this.drawingRemarkList = res.data.data;
        })
      },
    },
  };
</script>

<style scoped>

</style>